// files.path() 将相对路径转为绝对路径
// let myModelPath = files.path("./models");
// let result = paddle.ocr("/sdcard/Pictures/Screenshots/02.png", myModelPath);
// log(result)


function OCR(){
    //请求截图权限
    if (!requestScreenCapture(false)) {
        toast("请求截图失败");
        exit();
    }

    var img = captureScreen();
    var imgclip = images.clip(img,58,82,170,60);
    imgclip.saveTo("/sdcard/04.png");
    img.recycle();


    var url = "http://192.168.16.172:8080/aaa";
    var result = http.postMultipart(url,{
        file:open("/sdcard/04.png")
    })
    log(result)
    var json = result.body.json();
    log(json.core)
    log("mess=="+json.mess)
    return json.mess;
}

var resource = OCR()
var res = resource.split(";")
var MIN  = 2000
var flag = (resource=="" || res[0]<MIN || res[1]<MIN);
log(resource=="")
log(res[0]<MIN)
log(res[1]<MIN)
log(flag)



// img.saveTo("/sdcard/04.png");
// var imgclip = images.clip(images.read("/sdcard/04.png"),53,82,170,60)//223 142
//var img64 = images.toBase64(img,"png",100);
// imgclip.saveTo("/sdcard/05.png");


// var img = images.read("/sdcard/Pictures/Screenshots/02.png");
// var img2 = captureScreen();
// var img = images.toBase64(img2,"png",100);
// log(img.getWidth())
// var imgclip = images.clip(img,53,82,170,60)//223 142
// imgclip.saveTo("/sdcard/04.png")
// img.recycle();
// imgclip.recycle();


/*
var img = images.read("/sdcard/03.png");
var img64 = images.toBase64(img, "png", 100);
*/
/*
var API_Key="Dh3MNm0duvrOycp7XLRZqc6L";
var Secret_Key="GFUP1ZdksEurCh1CutXMqUWpRlwWGNVf";
//access_token获取地址。
var getTokenUrl="https://aip.baidubce.com/oauth/2.0/token";
var token_Res = http.post(getTokenUrl, {
    grant_type: "client_credentials",
    client_id: API_Key,
    client_secret: Secret_Key,
});
var access_token=token_Res.body.json().access_token;
//通用文字识别，50000次/天免费
var ocrUrl = "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic";
var ocr_Res = http.post(ocrUrl, {
    headers: {
        "Content - Type": "application/x-www-form-urlencoded"
    },
    access_token: access_token,
    image: img64,
    language_type:"CHN_ENG"
});
var json = ocr_Res.body.json();
log(json);
*/
/*
var file = img64;
var url = "http://192.168.16.172:8080/aaa";
var result = http.postMultipart(url,{
    file:open("/sdcard/03.png")
})
log(result)
var json = result.body.json();
log(json.core)
log(json.mess)

img.recycle();
*/